Skip to content

fix(physical-backup): Remove backup metadata when the backup fails (backport #662) - #663

Merged
regdocs merged 1 commit into
masterfrom
mergify/bp/master/pr-662
Nov 4, 2026
Merged

regdocs merged 1 commit into
masterfrom
mergify/bp/master/pr-662

Conversation

@mergify

@mergify mergify Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Problem

A physical backup writes physical_backup_meta.json into the data directory of each database (/var/lib/mysql/<db>/), so that the disk snapshot carries it. create_backup_job removed this file only at the end, after every step passed.

When a step failed, the file stayed. One example is Create Database Snapshot, when the snapshot request to press returns an HTTP error that the job does not retry. MariaDB does not know this file. So a later DROP DATABASE deletes the table files, but cannot remove the directory:

(1010, 'Error dropping database (can\'t rmdir \'./<db>\', errno: 39 "Directory not empty")')

Each site restore then fails at the Restore Site step, every time, until someone removes the file by hand on the database server.

Fix

  • Remove the metadata in a finally block, so that a failed backup also removes it.
  • In remove_backups_metadata, suppress errors for each database separately. Before, one missing file ended the loop, and the files of the other databases stayed.

Tests

agent/tests/test_database_physical_backup.py checks that the metadata goes after a successful backup, after a failed snapshot, and for every database when one file is already missing.

🤖 Generated with Claude Code


This is an automatic backport of pull request #662 done by Mergify.

The physical backup writes physical_backup_meta.json into each database
directory so that the snapshot carries it. The job removed the file only
after every step passed. When a step failed, for example when the snapshot
request to press returned an error, the file stayed behind. MariaDB does
not know this file, so a later DROP DATABASE could not remove the
directory and failed with errno 39 "Directory not empty". Site restores
then failed at the Restore Site step on every retry.

Remove the metadata in a finally block, so that it goes after a failed
backup too. Also suppress errors per database, so that one missing file
does not stop the cleanup of the other databases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 17d51c5)
@mergify mergify Bot assigned regdocs Nov 4, 2026
@mergify

mergify Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@regdocs
regdocs merged commit 2bb28db into master Nov 4, 2026
6 checks passed
@regdocs
regdocs deleted the mergify/bp/master/pr-662 branch November 4, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant